package org.csu.mypetstore.api.controller.front;

import org.csu.mypetstore.api.common.CommonResponse;
import org.csu.mypetstore.api.entity.Category;
import org.csu.mypetstore.api.service.CartService;
import org.csu.mypetstore.api.service.OrderService;
import org.csu.mypetstore.api.vo.BillAddressVO;
import org.csu.mypetstore.api.vo.CartVO;
import org.csu.mypetstore.api.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/Order/")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private CartService cartService;

//  生成订单
    @PostMapping("newOrder")
    @ResponseBody
    public CommonResponse<OrderVO> generateOrder(
            @RequestParam String shipAddr1,
            @RequestParam String shipAddr2,
            @RequestParam String shipCity,
            @RequestParam String shipState,
            @RequestParam String shipZip,
            @RequestParam String shipCountry,
            @RequestParam String billAddr1,
            @RequestParam String billAddr2,
            @RequestParam String billCity,
            @RequestParam String billState,
            @RequestParam String billZip,
            @RequestParam String billCountry,
            @RequestParam String courier,
            @RequestParam String billtofirstname,
            @RequestParam String billtolastname,
            @RequestParam String shiptofirstname,
            @RequestParam String shiptolastname,
            @RequestParam String creditcard,
            @RequestParam String cardtype,
            @RequestParam String locale,
            @RequestParam String expiryDate,
            @RequestParam String userid,
            HttpSession session) {
        return orderService.generateOrder(
                shipAddr1,
                shipAddr2,
                shipCity,
                shipState,
                shipZip,
                shipCountry,
                billAddr1,
                billAddr2,
                billCity,
                billState,
                billZip,
                billCountry,
                courier,
                billtofirstname,
                billtolastname,
                shiptofirstname,
                shiptolastname,
                creditcard,
                cardtype,
                locale,
                expiryDate,
                userid,
                session
        );
    }

    @GetMapping("orders")
    @ResponseBody
    public CommonResponse<List<OrderVO>> viewOrders(HttpSession session) {
        return orderService.viewOrders(session);
    }
}
